#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include"XECDH.h"
#include "TcpSocket.h"
#include <string>
using namespace std;
int main()
{
    // 1. 创建通信的套接字
    TcpSocket tcp;

    // 2. 连接服务器IP port
    int ret = tcp.connectToHost("127.0.0.1", 10000);
    if (ret == -1)
    {
        return -1;
    }

    // 3. 通信
   XECDH ecdh;
   unsigned char sp[1024]={0};
   ecdh.CreateKey();
   ecdh.GetPubKey(sp);
   // 发送数据
   tcp.sendMsg(string((char*)sp, strlen((char*)sp)));
   cout << "send Msg: " << endl;
   cout << sp << endl << endl << endl;
  
    // 接收数据
   string msg=tcp.recvMsg();
   //开始生成共享密钥
   unsigned char key[1024]={0};
   ecdh.SharedKey(key,(unsigned char*)msg.data(),msg.size());
   cout<<"seckey:"<<key<<endl;

    sleep(10);

    return 0;
}